﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<TopicEntity>>" %>
<%
    var _forum = ViewData["ForumDetail"] as Forum;
    var _pageUrl = ForumContext.ForumLink(_forum.ForumId, _forum.ForumName, "{0}");
    var _totalRows = Convert.ToInt32(ViewData["TotalRows"]);
    var _pageIndex = Convert.ToInt32(ViewData["PageIndex"]);
    var _pageRenderTemp = ForumContext.PageRender(_pageUrl, _pageIndex, ForumContext.Configuration.TopicsPerPage, _totalRows);

    bool _isMod = ForumContext.Logined &&(ForumContext.UserInfo.IsAdmin || ForumContext.UserInfo.IsModerated(_forum.ForumId));

    var _postLink = ForumContext.GetAbsoluteUrl(ForumUrls.POST);

    var _newPost = string.Format("window.location='{0}?sessionId={1}'", _postLink, ForumContext.Encrypt((int)CommandType.NewPost, _forum.ForumId));

    string _lockCmd=null, _unlockCmd=null;
    
        
%>
<div id="topic_quick_search" class="fr-widget popup-container">
    <table cellpadding="0" cellspacing="1" width="100%">
        <tr>
            <td class="popup-header">
                <%=ForumContext.GetText("FORUM","SEARCH_IN_FORUM")%>
            </td>
        </tr>
        <tr>
            <td class="table-cell align-center">
                <input id="_topic_kw" onkeydown="return TopicQuickSearch(event)" class="input search-input focus-no-addclass" />
            </td>
        </tr>
        <%-- <tr>
            <td><asp:RadioButton runat="server" Checked="true" GroupName="SearchResultType" ID="_ShowThreads"
            Text="Chủ đề" />
             <asp:RadioButton runat="server" Checked="true" GroupName="SearchResultType" ID="_ShowPosts"
            Text="Bài viết" />
            </td>
        </tr>--%>
        <tr>
            <td class="table-cell">
                <a href="<%=ForumContext.GetAbsoluteUrl(ForumUrls.SEARCH) %>">Tìm kiếm nâng cao</a>
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        function TopicQuickSearch(event) {
            if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {

                if ($('#_topic_kw').val().replace(' ', '').length > 0) {

                    window.location = '<%=ForumContext.GetAbsoluteUrl(ForumUrls.SEARCH) %>?do=quick&Id=<%=_forum.ForumId %>&kw=' + encodeURIComponent($('#_topic_kw').val());

                }

                return false;

            }
            return true;

        };
    </script>
</div>
<div class="white-space">
    <%=_pageRenderTemp%>
    <% if (_forum.AllowPostWithIn)
       {

           if (!_forum.IsLocked || (ForumContext.Logined && (ForumContext.UserInfo.IsAdmin || ForumContext.UserInfo.Permissions.PostWithinLockedForums)))
           {
    %>
    <button class="button-icon" onclick="<%=_newPost %>">
        <span class="icon-b icon-newtopic">&nbsp;</span> <span class="button-text">
            <%=ForumContext.GetText("Topics","NEW_TOPIC") %></span>
    </button>
    <%
        }
       }%>
    <% 
        
        if (ForumContext.Logined && ForumContext.UserInfo.IsAdmin)
        {
            if (_forum.IsLocked)
            {

                _unlockCmd = ForumContext.Encrypt((int)CommandType.UnLockForum, _forum.ForumId);
           

    %>
    <button class="button-icon" onclick="$.MvcForum.cmd('<%=_unlockCmd %>')">
        <span class="icon-b icon-unlock">&nbsp;</span> <span class="button-text">
            <%=ForumContext.GetText("Topics","UN_LOCK") %></span>
    </button>
    <%
}
            else
            {
                _lockCmd = ForumContext.Encrypt((int)CommandType.LockForum, _forum.ForumId);
    %>
    <button class="button-icon" onclick="$.MvcForum.cmd('<%=_lockCmd %>')">
        <span class="icon-b icon-lock">&nbsp;</span> <span class="button-text">
            <%=ForumContext.GetText("Topics","LOCK") %></span>
    </button>
    <%
        }
        }%>
</div>
<div class="fr-widget white-space">
    <div class="header">
        <div class="fr-options dropdown-menu {target:'#topic_quick_search'}">
            <a href="javascript:void(0)">
                <%=ForumContext.GetGlobalText("SEARCH")%></a>
        </div>
        <div class="icon">
        </div>
        <h1>
            <%=Html.Encode(_forum.ForumName)%>
        </h1>
    </div>
    <table cellpadding="0" cellspacing="1" width="100%">
        
        <tr>
         <%if (_isMod)
                {%>
                <td class="table-header w5">
                     &nbsp;
                </td>
                <%
                }%>        
            <td class="table-header width5">
                &nbsp;
            </td>
            <td class="table-header">
                <%=ForumContext.GetText("TOPICS","TOPIC") %>
            </td>
            <td class="table-header width20">
                <%=ForumContext.GetText("TOPICS","LAST_POST") %>
            </td>
            <td class="table-header width10">
                <%=ForumContext.GetText("TOPICS","TOTALPOSTS") %>
            </td>
            <td class="table-header width10">
                <%=ForumContext.GetText("TOPICS","TOTALVIEWS") %>
            </td>
        </tr>
        <%
            
            if (Model != null)
            {

               
                
                int _colspan = _isMod? 6: 5;

                var PriorityTopics = Model.Where(x => x.Priority > 0);

                if (PriorityTopics != null && PriorityTopics.Count() > 0)
                {
                
                
        %>
        <tr>
            <td colspan="<%=_colspan %>" class="table-caption">
               <%=ForumContext.GetText("TOPICS", "PRIORITY_TOPICS")%>
            </td>
        </tr>
        <%
            foreach (var topic in PriorityTopics)
            {
  
                    
        %>
        <tr class="<%=!topic.IsApproved?"fr-post-queue":string.Empty %> <%=topic.IsDeleted?"fr-post-deleted":string.Empty %>">
            <%if (_isMod)
                {%>

                <td class="table-cell w5">
                    <input type="checkbox" class="item-selected" value="<%=topic.TopicId %>" />
                </td>
                <%
                }%>
            <td class="table-cell table-cell-height center">
                <%=ForumContext.TopicIcon(topic) %>
            </td>
            <td class="table-cell-alter">
                <% if (!string.IsNullOrEmpty(topic.Icon))
                   {%>
                <img class="smile" src="<%=ForumContext.Configuration.TopicSmiles+topic.Icon %>" alt="<%=topic.Icon %>" />
                <%
                    }%>
               <%-- <a class="fr-subject" href="<%=ForumContext.ThreadLink(topic.TopicId,topic.TopicName,null) %>"
                    title="<%=Html.Encode(topic.TopicName) %>">
                    <%=Html.Encode(topic.TopicName) %></a>--%>
                    <%=ForumContext.TopicLink(topic) %>
                    <br />
                <%=string.Format(ForumContext.GetGlobalText("POSTER"), topic.UserName, ForumContext.GetAbsoluteUrl(ForumUrls.USER_INFO, topic.UserName))%>
            </td>
            <td class="table-cell">
                <% if (!topic.LastPostId.HasValue || topic.LastPostId.Value == 0)
                   {%>
                <a title="<%=ForumContext.GetText("Topics", "VIEW_LAST_POST") %>" href="<%=ForumContext.ThreadLink(topic.TopicId,topic.TopicName,null) %>"
                    class="last-post"><span class="post-date">
                        <%=ForumContext.PrettyDate(topic.Created)%></span></a><br />
                <%=string.Format(ForumContext.GetGlobalText("POSTER"), topic.UserName, ForumContext.GetAbsoluteUrl(ForumUrls.USER_INFO, topic.UserName))%>
                <%
                    }

                   else
                   {
                %>
                <a title="<%=ForumContext.GetText("Topics", "VIEW_LAST_POST") %>" href="<%=ForumContext.FindPost(topic.LastPostId.Value,topic.TopicName)%>"
                    class="last-post"><span class="post-date">
                        <%=ForumContext.PrettyDate(topic.LastPosted)%></span></a><br />
                <%=string.Format(ForumContext.GetGlobalText("POSTER"), topic.LastUserName, ForumContext.GetAbsoluteUrl(ForumUrls.USER_INFO, topic.LastUserName))%>
                <%
                    }
                %>
            </td>
            <td class="table-cell-alter center">
                <%=topic.TotalReplies %>
            </td>
            <td class="table-cell center">
                <%=topic.TotalViews %>
            </td>
        </tr>
        <%
}
                }
        %>
        <%
            var Topics = Model.Where(x => x.Priority == 0);

            if (Topics != null)
            {


        %>
        <tr>
            <td colspan="<%=_colspan %>" class="table-caption">
                Chủ đề của diễn đàn
            </td>
        </tr>
        <%
            foreach (var topic in Topics)
            {


        %>
        <tr class="<%=!topic.IsApproved?"fr-post-queue":string.Empty %> <%=topic.IsDeleted?"fr-post-deleted":string.Empty %>">
            
            <%if (_isMod)
                {%>

                <td class="table-cell w5">
                    <input type="checkbox" class="item-selected" value="<%=topic.TopicId %>" />
                </td>
                <%
                }%>
            <td class="table-cell table-cell-height">
                <%=ForumContext.TopicIcon(topic) %>
            </td>
            <td class="table-cell-alter">
                <% if (!string.IsNullOrEmpty(topic.Icon))
                   {%>
                <img src="<%=ForumContext.Configuration.TopicSmiles+topic.Icon %>" alt="<%=topic.Icon %>"
                    class="smile" />
                <%
                    }%>
               <%=ForumContext.TopicLink(topic) %><br />
                <%=string.Format(ForumContext.GetGlobalText("POSTER"), topic.UserName, ForumContext.GetAbsoluteUrl(ForumUrls.USER_INFO, topic.UserName))%>
            </td>
            <td class="table-cell">
                <% if (!topic.LastPostId.HasValue || topic.LastPostId.Value == 0)
                   {%>
                <a title="<%=ForumContext.GetText("Topics", "VIEW_LAST_POST") %>" href="<%=ForumContext.FindPost(topic.TopicId,topic.TopicName)  %>"
                    class="last-post"><span class="post-date">
                        <%=ForumContext.PrettyDate(topic.Created)%></span></a><br />
                <%=string.Format(ForumContext.GetGlobalText("POSTER"), topic.UserName, ForumContext.GetAbsoluteUrl(ForumUrls.USER_INFO, topic.UserName))%>
                <%
                    }

                   else
                   {
                %>
                <a title="<%=ForumContext.GetText("Topics", "VIEW_LAST_POST") %>" href="<%=ForumContext.FindPost(topic.LastPostId.Value,topic.TopicName)  %>"
                    class="last-post"><span class="post-date">
                        <%=ForumContext.PrettyDate(topic.LastPosted)%></span></a><br />
                <%=string.Format(ForumContext.GetGlobalText("POSTER"), topic.LastUserName, ForumContext.GetAbsoluteUrl(ForumUrls.USER_INFO, topic.LastUserName))%>
                <%
                    }
                %>
            </td>
            <td class="table-cell-alter center">
                <%=topic.TotalReplies%>
            </td>
            <td class="table-cell center">
                <%=topic.TotalViews%>
            </td>
        </tr>
        <%

            }

            }

            }
        %>
    </table>
</div>

<%
    if (_isMod){ Html.RenderPartial("ModerationTools");}
       %>

<div class="white-space">
    <%=_pageRenderTemp%>
    <% if (_forum.AllowPostWithIn)
       {

           if (!_forum.IsLocked || (ForumContext.Logined && (ForumContext.UserInfo.IsAdmin || ForumContext.UserInfo.Permissions.PostWithinLockedForums)))
           {
    %>
    <button class="button-icon" onclick="<%=_newPost %>">
        <span class="icon-b icon-newtopic">&nbsp;</span> <span class="button-text">
            <%=ForumContext.GetText("Topics","NEW_TOPIC") %></span>
    </button>
    <%
        }
       }%>
    <% 
        
        if (ForumContext.Logined && ForumContext.UserInfo.IsAdmin)
        {
            if (_forum.IsLocked)
            {

           

    %>
    <button class="button-icon" onclick="$.MvcForum.cmd('<%=_unlockCmd %>')">
        <span class="icon-b icon-unlock">&nbsp;</span> <span class="button-text">
            <%=ForumContext.GetText("Topics","UN_LOCK") %></span>
    </button>
    <%
}
            else
            {
    %>
    <button class="button-icon" onclick="$.MvcForum.cmd('<%=_lockCmd %>')">
        <span class="icon-b icon-lock">&nbsp;</span> <span class="button-text">
            <%=ForumContext.GetText("Topics","LOCK") %></span>
    </button>
    <%
        }
        }%>
</div>
<div class="fr-widget white-space">
    <div class="header">
        <div class="collapse collapse-close {collapseId:'#collapse_panel_topic_key'}">
        </div>
        <div class="icon">
        </div>
        <span><%=ForumContext.GetText("TOPICS","TOPIC_KEY") %></span>
    </div>
    <div id="collapse_panel_topic_key">
    <table cellpadding="0" cellspacing="1" width="100%">
            <tr>
                <td class="table-cell">
                    <div class="topic-key topic-new">
                        <%=ForumContext.GetText("Topics","TOPIC_NEW") %></div>
                </td>
                <td class="table-cell">
                    <div class="forum-key topic-locked-new">
                        <%=ForumContext.GetText("Topics","TOPIC_LOCKED_NEW")%></div>
                </td>
            </tr>
            <tr>
                <td class="table-cell">
                    <div class="topic-key topic-not-new">
                        <%=ForumContext.GetText("Topics","TOPIC_NOT_NEW")%></div>
                </td>
                <td class="table-cell">
                    <div class="topic-key topic-locked">
                        <%=ForumContext.GetText("Topics","TOPIC_LOCKED")%></div>
                </td>
            </tr>
            <tr>
                <td class="table-cell">
                    <div class="topic-key topic-poll">
                        <%=ForumContext.GetText("Topics","TOPIC_POLL")%></div>
                </td>
                <td class="table-cell">
                    <div class="topic-key topic-hot-new">
                        <%=ForumContext.GetText("Topics","TOPIC_HOT_NEW")%></div>
                </td>
            </tr>
            <tr>
                <td class="table-cell">
                    <div class="topic-key topic-poll-new">
                        <%=ForumContext.GetText("Topics","TOPIC_POLL_NEW")%></div>
                </td>
                <td class="table-cell">
                    <div class="topic-key topic-hot">
                        <%=ForumContext.GetText("Topics","TOPIC_HOT")%></div>
                </td>
            </tr>
            <tr>
                <td class="table-cell">
                    <div class="topic-key topic-link">
                        <%=ForumContext.GetText("Topics","TOPIC_LINK")%></div>
                </td>
                <td class="table-cell">
                    <div class="topic-key topic-moved">
                        <%=ForumContext.GetText("Topics","TOPIC_MOVED")%></div>
                </td>
            </tr>
        </table>        
    </div>
</div>
